package com.system.announcement.web;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.system.announcement.entity.Announcement;
import com.system.announcement.service.IAnnouncementService;
import com.system.common.util.ExtAjaxResponse;
import com.system.common.util.ExtPageable;
import com.system.employee.entity.Employee;

@Controller
@RequestMapping("/announcement")
public class AnnouncementController {
	@Autowired
	private IAnnouncementService announcementService;
	@RequestMapping("/saveOrUpdate")
	public @ResponseBody ExtAjaxResponse saveOrUpdate(Announcement a) 
	{	
		
			try {
				announcementService.saveOrUpdate(a);
				return new ExtAjaxResponse(true,"添加公告成功！");
			} catch (Exception e) {
				System.out.println(e);
				return new ExtAjaxResponse(false,"添加公告失败！");
			}
		
		
	}
	@RequestMapping("/findLast")
	public @ResponseBody Announcement findLast() 
	{	
			
	    return announcementService.findLast();
	
	}
	@RequestMapping("/delete")
	public @ResponseBody ExtAjaxResponse delete(@RequestParam Long id) 
	{
		try {
			Announcement a =  announcementService.findOne(id);
			if(null!=a) {
				announcementService.delete(a);
			}
			return new ExtAjaxResponse(true,"操作成功！");
		} catch (Exception e) {
			System.out.println(e);
			return new ExtAjaxResponse(false,"操作失败！");
		}
	}
	@RequestMapping("/deletes")
	public @ResponseBody ExtAjaxResponse deleteEmployees(@RequestParam Long[] ids) 
	{
		try {
			List<Long> idLists = Arrays.asList(ids);
			if(null!=idLists) {
				announcementService.delete(idLists);
			}
			return new ExtAjaxResponse(true,"操作成功！");
		} catch (Exception e) {
			return new ExtAjaxResponse(false,"操作失败！");
		}
	}
	@RequestMapping("/findPage")
	public @ResponseBody Page<Announcement> findPage(ExtPageable pageable){
		
		return announcementService.findAll(pageable.getPageable());
		
	}

}
